<script>
	export default {
		data() {
			return {
				version: '',
				wgtUrl: "https://youpindou.com:8083/doudougou/download/app?type=wgt",
				appUrl: 'https://youpindou.com:8083/doudougou/download/app'
			}
		},
		onLaunch: function() {
			// #ifdef APP-PLUS
			let that = this
			const appleId = '6469492281'
			const type = 2 //暂无字段
			const platform = uni.getSystemInfoSync().platform.toLowerCase();
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				that.$request.systemSettingsGet({
					key: 'curr_wgt_version'
				}).then(res => {
					if (res.code == 200 && res.isSuccess) {
						uni.setStorageSync('version', res.data.settingValue);
						let appCode = res.data.settingValue.split('.').join('');
						let version = widgetInfo.version.split('.').join('');
						console.log(appCode, '服务器版本')
						console.log(version, '当前版本')
						// wgt服务器2.0.12
						// 在打.wgt包的时候，manifest.json一定要比服务器上的版本号和版本名称小才可以安装成功，不然会报错
						// type == 1 整包更新  type == 2 热更新
						if (type == 1) {
							if (platform == 'android') {
								// 安卓打开网页下载
								plus.runtime.openURL(that.appUrl);
							} else {
								uni.showModal({
									title: '发现新版本 ',
									content: '是否前往App store进行升级',
									success: function(res) {
										if (res.confirm) {
											plus.runtime.launchApplication({
												action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
											})
										}
									}
								})
							}
						} else if (type == 2) {
							// 如果服务器的版本号大于当前的版本号，那就是有版本更新
							// version => 当前版本
							// appCode => 服务器版本
							if (appCode > version) {
								if (platform == 'android') {
									uni.navigateTo({
										url: '/pages/premiumBag/home/upgrade'
									})
								} else {
									uni.showModal({
										title: '发现新版本 ',
										content: '是否前往App store进行升级',
										success: function(res) {
											if (res.confirm) {
												plus.runtime.launchApplication({
													action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
												})
											}
										}
									})
								}
							}
						}
					}
				})
			});
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	
	@import "@/uni_modules/uview-ui/index.scss";

	page {
		background: #fff;
		height: 100%;
	}


	.flexCol {
		display: flex;
		flex-direction: column;
	}

	.flexRow {
		display: flex;
		flex-direction: row;
	}

	.End {
		display: flex;
		align-items: center;
	}

	.Ends {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.align {
		text-align: center;
	}

	.oneText {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.twoText {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/*显示的行数*/
		overflow: hidden;
	}

	.cover-image {
		height: 68rpx;
		width: 68rpx;
		position: fixed;
		/* #ifdef APP-PLUS */
		position: absolute;
		/* #endif */
		top: 50%;
		left: 50%;
		margin-top: -30rpx;
		margin-left: -30rpx;
	}

	.zIndex {
		z-index: 9999999;
	}
</style>